package com.teira.rhrrealstate.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.teira.rhrrealstate.entity.ZonaGeografica;
import com.teira.rhrrealstate.session.ZonaGeograficaHome;

@Name("zonaGeograficaConverter")
@BypassInterceptors
@org.jboss.seam.annotations.faces.Converter(forClass=ZonaGeografica.class)
public class ZonaGeograficaConverter implements Converter {

	ZonaGeograficaHome zonaGeograficaHome = (ZonaGeograficaHome) Component.getInstance(ZonaGeografica.class);
	
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
		if(value == null)
			return null;
		return zonaGeograficaHome.getEntityManager().find(ZonaGeografica.class, new Long(value));
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		return value != null && ((ZonaGeografica)value).getId() != null ? ((ZonaGeografica)value).getId().toString() : "";
	}


}
